import {defineStore} from 'pinia';
import utils from '@/utils';

const AccessTokenKey = 'authUser';

interface State {
	userAnswer: {template: string; userAnswer: string[]|{text?:string,audios?:string[],pics?:string[]}[];}[];
	currentAudio: HTMLAudioElement | null

}

export const useDataStore = defineStore('useDataStore', {
	state: (): State => {
		return {
			userAnswer: [],
			currentAudio: null
		};
	},
	getters: {},
	actions: {
		setUser(payload: any) {
			this.$patch(payload);
			utils.setStorage(AccessTokenKey, payload);
		},
		setUserAnswer(payload: any, index: number) {
			this.userAnswer[index] = payload;
		},
		// 字段重置
		clearUser() {
			this.userAnswer = [];
			this.$reset();
		},
	},
});

